<template>
  <view class="content">
    <template>
      <uni-notice-bar @click="showNotice" :text="noticeText" scrollable showIcon="true" backgroundColor="#f3fffe"
        color="#2abbaf" fontSize="16" />
    </template>
  </view>
</template>

<script setup>
  import {
    ref,
    onMounted
  } from 'vue'
  import * as http from '@/utils/http'
  const notices = ref([]);
  const noticeText = ref();
  const currentIndex = ref(0)
  onMounted(async () => {
    let param = {
      pageNo: 1,
      pageSize: 10
    }
    const result = await http.getRequest("/xhyy/notice/page", param)
    if (result.code == 0) {
      notices.value = result.data.list
      noticeText.value = notices.value[0].title + notices.value[0].content
    } else {
      uni.showToast({
        title: '获取通知失败',
        icon: 'error',
        duration: 1000
      })
    }
  })
  setInterval(() => {
    currentIndex.value = (currentIndex.value + 1) % notices.value.length;
    noticeText.value = notices.value[currentIndex.value].title + notices.value[currentIndex.value].content
  }, 9000); // 每3秒更新一次通知

  function showNotice() {
    uni.showModal({
      showCancel: false,
      content: noticeText.value
    })
  }
</script>

